<?php


namespace app\lunwen\controller;


use app\lunwen\model\StuTopicLogModel;
use app\lunwen\model\StuTopicModel;
use cmf\controller\HomeBaseController;
    //老师审查课题
class TeacherExamineTitleController extends HomeBaseController
{
    public function index(){

        $tea_title = new StuTopicModel();
        $data = $tea_title->where('status','in',"已提交,修改课题,导师通过,导师不通过")
            ->where("stu_teacher",session("teacher_name"))
            ->whereTime('create_time','>',session('beforeYear'))
            ->whereTime('create_time','<',session('afterYear'))
            ->all();
        $this->assign('title',$data);
        return $this->fetch(':teacherExamineTitle');
    }

    //查看全部课题
    public function all(){
        //返回 列表
        //直接查询 学生选题 表
        //把对应的状态 改成文字
        $tea_title = new StuTopicModel();
        $data = $tea_title->where('status','in',"已提交,修改课题,导师通过,导师不通过")
            ->where("stu_teacher",session("teacher_name"))
            ->whereTime('create_time','>',session('beforeYear'))
            ->whereTime('create_time','<',session('afterYear'))
            ->all();
        $this->assign('title',$data);
        return $this->fetch(':teacherExamineTitle');

    }

    //查看未审批的课题
    public function noExamine(){
        //查询学生选题表 状态为 1、7的
        $tea_title = new StuTopicModel();
        $data = $tea_title->where('status','in',"已提交,修改课题")
            ->where("stu_teacher",session("teacher_name"))
            ->whereTime('create_time','>',session('beforeYear'))
            ->whereTime('create_time','<',session('afterYear'))
            ->all();
        $this->assign('title',$data);
        return $this->fetch(':teacherExamineTitle');
    }

    //已审批的课题
    public function alreadyExamine(){
        //查询学生选题表  状态为 2.3的
        $tea_title = new StuTopicModel();
        $data = $tea_title->where('status','in',"导师通过,导师不通过")
            ->where("stu_teacher",session("teacher_name"))
            ->whereTime('create_time','>',session('beforeYear'))
            ->whereTime('create_time','<',session('afterYear'))
            ->all();
        $this->assign('title',$data);
        return $this->fetch(':teacherExamineTitle');
    }

    //点击通过
    public function pass(){
        //获取当前元素的 父父元素 拿到里面的值 放到数组中去
        //判断 当前的状态 是否是1、7 是就通过 改变状态为2 加入日志表
        echo $_GET['stu_name'];
        echo $_GET['stu_id'];
        //查出当前这一条的数据
        $title = new StuTopicModel();
        $data = $title->where('stu_id',$_GET['stu_id'])->find();
        //var_dump ($data);
        if($data->status=="已提交"||$data->status=="修改课题"){
           //改状态
            $teacher_jg = new StuTopicModel();
            $teacher_jg->save(
                ['status'=>'导师通过'],
                ['stu_id'=>$_GET['stu_id']]
            );

            //保存日志

            //echo $data->stu_title;
            $teacher_jg_log = new StuTopicLogModel();
            $teacher_jg_log->stu_name=$_GET['stu_name'];
            $teacher_jg_log->title=$data->stu_title;
            $teacher_jg_log->status='导师通过';
            $teacher_jg_log->stu_teacher=session("teacher_name");
            $teacher_jg_log->stu_id=$_GET['stu_id'];
            $teacher_jg_log->save();

            //回到页面
            $tea_title = new StuTopicModel();
            $data = $tea_title->where('status','in',"已提交,修改课题,导师通过,导师不通过")
                ->where("stu_teacher",session("teacher_name"))
                ->whereTime('create_time','>',session('beforeYear'))
                ->whereTime('create_time','<',session('afterYear'))
                ->all();
            $this->assign('title',$data);
            return $this->fetch(':teacherExamineTitle');
        }
       else{
           //不是1或者7的状态不修改
           $this->assign('msg',"当前状态不能审批");
           //返回 列表
           //直接查询 学生选题 表
           //把对应的状态 改成文字
           $tea_title = new StuTopicModel();
           $data = $tea_title->where('status','in',"已提交,修改课题,导师通过,导师不通过")
               ->where("stu_teacher",session("teacher_name"))
               ->whereTime('create_time','>',session('beforeYear'))
               ->whereTime('create_time','<',session('afterYear'))
               ->all();
           $this->assign('title',$data);
           return $this->fetch(':teacherExamineTitle');
       }

    }

    //点击不通过
    public function notpass(){
        //获取当前元素的 父父元素 拿到里面的值 放到数组中去
        //判断 当前的状态 是否是1、7 是就不通过 改变状态为3 加入日志表
        echo $_GET['stu_name'];
        echo $_GET['stu_id'];
        //查出当前这一条的数据
        $title = new StuTopicModel();
        $data = $title->where('stu_id',$_GET['stu_id'])->find();
        //var_dump ($data);

        if($data->status=="已提交"||$data->status=="修改课题"){
            //改状态
            $teacher_jg = new StuTopicModel();
            $teacher_jg->save(
                ['status'=>'导师不通过'],
                ['stu_id'=>$_GET['stu_id']]

            );

            //保存日志

            //echo $data->stu_title;
            $teacher_jg_log = new StuTopicLogModel();
            $teacher_jg_log->stu_name=$_GET['stu_name'];
            $teacher_jg_log->title=$data->stu_title;
            $teacher_jg_log->stu_teacher=session("teacher_name");
            $teacher_jg_log->status='导师不通过';
            $teacher_jg_log->stu_teacher=session("teacher_name");
            $teacher_jg_log->stu_id=$_GET['stu_id'];
            $teacher_jg_log->save();

            $tea_title = new StuTopicModel();
            $data = $tea_title->where('status','in',"已提交,修改课题,导师通过,导师不通过")
                ->where("stu_teacher",session("teacher_name"))
                ->whereTime('create_time','>',session('beforeYear'))
                ->whereTime('create_time','<',session('afterYear'))
                ->all();
            $this->assign('title',$data);
            return $this->fetch(':teacherExamineTitle');
        }
        else{
            //不是1或者7的状态不修改
            $this->assign('msg',"当前状态不能审批");
            //返回 列表
            //直接查询 学生选题 表
            //把对应的状态 改成文字
            $tea_title = new StuTopicModel();
            $data = $tea_title->where('status','in',"已提交,修改课题,导师通过,导师不通过")
                ->where("stu_teacher",session("teacher_name"))
                ->whereTime('create_time','>',session('beforeYear'))
                ->whereTime('create_time','<',session('afterYear'))
                ->all();
            $this->assign('title',$data);
            return $this->fetch(':teacherExamineTitle');
        }
    }
}